package gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class MyLayeredPane extends JLayeredPane implements MouseWheelListener {
	//public static HashMap layerPanels = new HashMap();
	//public static int layeredKey = 100;
	
	public MyLayeredPane() {
		super();
		addMouseWheelListener(this);
	}

	public void addInLayer(MyScrollPane scrollPane) {
		//MyScrollPane scrollPane = new MyScrollPane(layeredKey++);
		//scrollPane.setViewportView(textPane);
		//scrollPane.setBounds(10, 50, 875, 300);
		
		//layerPanels.put("-"+scrollPane.getId()+"-", scrollPane);
		add(scrollPane, JLayeredPane.DEFAULT_LAYER);
	}

	public void removeLayer(MyTextPane textPane) {
		//JViewport comp = scrollPane.getViewport();
		//System.out.println(comp.getView());
		
		//if(layerPanels.containsKey("-100-")){
			//remove((MyScrollPane)layerPanels.get("-100-"));
			//layerPanels.remove("-100-");
		//}
		remove(textPane);
	}

	public void setJPanelSOUTH() {
		
	}
	
	public void setText(){
		Component[] component = getComponentsInLayer(JLayeredPane.DEFAULT_LAYER);
		if(component.length > 0){
			MyScrollPane curScrollPane= (MyScrollPane)component[0];
			Container parent = this.getParent();
			MyGlassPane glassPane = (MyGlassPane)this.getRootPane().getGlassPane();
			glassPane.setText(curScrollPane.getId());
		}
	}

	public void mouseWheelMoved(MouseWheelEvent e) {
		int rotation = e.getWheelRotation();
		int top = getComponentCountInLayer(JLayeredPane.DEFAULT_LAYER);
		if(top > 0){
			Component[] component = getComponentsInLayer(JLayeredPane.DEFAULT_LAYER);
			
			if (rotation > 0) {
				moveToBack(component[0]);
			} else {
				moveToFront(component[top - 1]);
			}
			setText();
		}
	}
}
